//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.eResearch.Common.Eventing
{
    using System;
    using System.Runtime.CompilerServices;

    /// <summary>
    /// Contains extension methods for raising (firing) events.
    /// </summary>
    public static class EventHelper
    {
        /// <summary>
        /// Fires the specified event handler delegate with the specified sender and event args.
        /// </summary>
        /// <typeparam name="TArgs">The type of the event args.</typeparam>
        /// <param name="handler">The event handler delegate.</param>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="args">The event arguments.</param>
        [MethodImpl(MethodImplOptions.NoInlining)]
        public static void Fire<TArgs>(this EventHandler<TArgs> handler, object sender, TArgs args) where TArgs : EventArgs
        {
            EventHandler<TArgs> handlerClone = handler;
            if (handlerClone != null)
            {
                handlerClone(sender, args);
            }
        } 
    }
}
